/* 
 * File:   zipFileDecompression.h
 * Author: Enrique Antezana
 *
 * Created on 4 de abril de 2013, 03:29 PM
 */

#ifndef ZIPFILEDECOMPRESSOR_H
#define	ZIPFILEDECOMPRESSOR_H
#include "../list/GenericList.h"

struct FileHeaderInfo
{
public:
    int header_;
    short size_;
    short flag_;
    short compressedMethod_;
    short extraFieldLength_;
    int compressedSize_;
    int unCompressedSize_;
    int crc_;
    char* fileFullPathName_;
    char* fileData_;

    FileHeaderInfo()
    {
        header_ = 0;
        size_ = 0;
        flag_ = 0;
        compressedMethod_ = 0;
        extraFieldLength_ = 0;
        compressedSize_ = 0;
        unCompressedSize_ = 0;
        crc_ = 0;
        fileFullPathName_ = 0;
        fileData_ = 0;

    }

    FileHeaderInfo & operator=(const FileHeaderInfo & other)
    {

        this->header_ = other.header_;
        this->size_ = other.size_;
        this->flag_ = other.flag_;
        this->compressedMethod_ = other.compressedMethod_;
        this->extraFieldLength_ = other.extraFieldLength_;
        this->compressedSize_ = other.compressedSize_;
        this->unCompressedSize_ = other.unCompressedSize_;
        this->crc_ = other.crc_;
        fileFullPathName_ = (char*) malloc(strlen(other.fileFullPathName_) + 1);
        strcpy(this->fileFullPathName_, other.fileFullPathName_);
        fileFullPathName_[strlen(other.fileFullPathName_)] = 0;
        fileData_ = (char*) malloc(other.unCompressedSize_);
        //to do
        memcpy(this->fileData_, other.fileData_, unCompressedSize_);

        return *this;
    }

    void setHeader(int header)
    {
        header_ = header;
    }

    void setSize(short size)
    {
        size_ = size;
    }

    void setFlag(short flag)
    {
        flag_ = flag;
    }

    void setCompressedMethod(short compressedMethod)
    {
        compressedMethod_ = compressedMethod_;
    }

    void setExtraFieldLength(short extraFieldLength)
    {
        extraFieldLength_ = extraFieldLength;
    }

    void setCompressedSize(int compressedSize)
    {
        compressedSize_ = compressedSize;
    }

    void setUncompressedSize(int unCompressedSize)
    {
        unCompressedSize_ = unCompressedSize;
    }

    void setCRC(unsigned long crc)
    {
        crc_ = crc;
    }

    void setFileFullPathName(const char* fileFullPathName)
    {
        fileFullPathName_ = (char*) malloc(sizeof (char) *(strlen(fileFullPathName) + 1));
        strcpy(fileFullPathName_, fileFullPathName);
        fileFullPathName_[strlen(fileFullPathName)] = 0;
    }

    void setFileData(const char* fileData)
    {
        fileData_ = (char*) malloc(sizeof (char) *strlen(fileData));
        strcpy(fileData_, fileData); //to do file data length using memcpy
    }

    ~FileHeaderInfo()
    {
    }

    FileHeaderInfo(FileHeaderInfo&);
    FileHeaderInfo& operator =(FileHeaderInfo&);
};

class ZipFileDecompressor
{
public:
    FILE* file_;
    GenericList<FileHeaderInfo*> headersInfo_;
    char* destinyPath_;

    ZipFileDecompressor(const char* filePath, const char* destinyPath);
    ~ZipFileDecompressor();
    FILE* createFile(char* fileName);
    void putFileContent(FILE* file, char* fileData);
    void createDirectory(const char* pathName);
    void decompress();
    GenericList<FileHeaderInfo*> navigate();

};

#endif	/* ZIPFILEDECOMPRESSOR_H */

